package com.simit.mapper;

import com.simit.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("userMapper")
public interface UserMapper {
    List<User> selectAll();

    @Select("select * from user where username = #{username} and password = #{password}")
    User select(@Param("username") String username, @Param("password") String password);

    @Select("select * from user where username = #{username}")
    User selectByUsername(String username);

    @Insert("insert into user values (null, #{username}, #{password})")
    void add(User user);

    @Update("update user set money = money + #{moneyAdd} where username = #{username}")
    void addMoney(@Param("username") String username, @Param("moneyAdd") int moneyAdd);

    @Update("update user set money = money - #{moneySubtract} where username = #{username}")
    void subtractMoney(@Param("username") String username, @Param("moneySubtract") int moneySubtract);
}